/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jmooc.service;

import com.jmooc.dao.UserCertificationDao;
import com.jmooc.entity.User;
import com.jmooc.entity.UserCertification;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jms.Connection;

/**
 *
 * @author Group
 */
@Stateless
public class UserCertificationService implements Serializable {
     
    @EJB
    private UserCertificationDao userCertificationDao;
    
    
    public void create(UserCertification UserCertification) {
        userCertificationDao.create(UserCertification);
    }
    
    public List<UserCertification> getAllByUser(User user) {
        return userCertificationDao.getAllByUser(user);
    }

    public UserCertification getById(Long certificationId) {
        return userCertificationDao.getById(certificationId);
    }
    
    // Print certification
    /*
    @Resource(mappedName="JmoocConnectionFactory")
    private ConnectionFactory connectionFactory;
     
    @Resource(mappedName="JmoocPrinterQueue")
    private Destination destination;
    */
    public void print(UserCertification certification) {
        
        Connection connection = null;
        /*
        try {
            connection = connectionFactory.createConnection();
            
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            
            MessageProducer producer = session.createProducer(destination);
            
            TextMessage message = session.createTextMessage(
                    "fname: " + certification.getUser().getFirstName() + ";" +
                    "lname: " + certification.getUser().getLastName()+ ";" +
                    "date" + certification.getObtentionDate());
            
            producer.send(message);
            
        } catch (JMSException ex) {
            System.out.println(ex.getMessage());
        } finally {
            if(null != connection) {
                try {
                    connection.close();
                } catch (JMSException ex) {
                    System.out.println(ex.getMessage());
                }
            }
        }
        */
    }
}
